var o = require("FFE95507875DE5CF998F3D00DB5D6824.js"), e = o.apiDomain, n = o.appName, t = function(o) {
    return (o = o.toString())[1] ? o : "0" + o;
};

module.exports = {
    formatTime: function(o) {
        var e = o.getFullYear(), n = o.getMonth() + 1, a = o.getDate(), s = o.getHours(), c = o.getMinutes(), i = o.getSeconds();
        return [ e, n, a ].map(t).join("/") + " " + [ s, c, i ].map(t).join(":");
    },
    getApps: function() {
        return new Promise(function(e, n) {
            wx.request({
                url: o.apiDomain + "/mp/apps",
                method: "GET",
                data: {
                    app_name: o.appName
                },
                success: function(o) {
                    console.log("success get apps", o), 200 != o.statusCode && (console.log(o), e([]));
                    var n = o.data.result;
                    e(n);
                },
                fail: function(o) {
                    n([]);
                }
            });
        });
    },
    wxlogin: function() {
        return console.log("wx.login"), new Promise(function(o, t) {
            wx.login({
                success: function(a) {
                    console.log("wx login success:", a), wx.request({
                        url: e + "/mp/login",
                        method: "POST",
                        data: {
                            app_name: n,
                            code: a.code
                        },
                        header: {
                            "content-type": "application/x-www-form-urlencoded"
                        },
                        success: function(e) {
                            console.log("请求mp/login完成", e), 200 == e.data.code ? o(e.data.result) : t(e);
                        },
                        fail: function(o) {
                            t(o);
                        }
                    });
                },
                fail: function(o) {
                    console.log("wx.login fail", o);
                }
            });
        });
    },
    reportError: function(e) {
        var n = JSON.stringify(e);
        wx.request({
            url: o.apiDomain + "/log",
            method: "POST",
            data: {
                app_name: o.appName,
                type: "error",
                content: n.substring(0, 1e4)
            },
            success: function() {
                console.log("上报错误成功");
            },
            fail: function() {
                console.log("上报错误失败");
            }
        });
    },
    getAd: function(e, n) {
        return new Promise(function(t, a) {
            wx.request({
                url: o.apiDomain + "/mp/ad",
                method: "GET",
                data: {
                    app_name: e,
                    page: n
                },
                success: function(o) {
                    if (console.log("success get ad:", e, n), 200 == o.statusCode) {
                        var a = o.data.result;
                        return console.log(a), t(a);
                    }
                    console.log(o);
                },
                fail: function(o) {
                    return console.log("failto get ad"), console.log(o), a([]);
                }
            });
        });
    },
    todayDate: function() {
        var o = new Date();
        return o.getFullYear() + "_" + (o.getMonth() + 1) + "_" + o.getDate();
    }
};